# 图书类
class Book:
  def __init__(self, title, author, publish_date):
    self.title = title
    self.__author = author
    self.__publish_date = publish_date

  def get_title(self):
    return self.title

  def get_author(self):
    return self.__author

  def get_pubdate(self):
    return self.__publish_date


# 图书馆类
class Library:

  def __init__(self, name):
    self.name = name
    self.books = []
    self.origin_books = []

  def add_book(self, book):
    """
    添加图书
    :param book: 传入的Book对象
    """
    self.books.append(book)
    self.origin_books.append(book)

  def borrow_book(self, title):
    '''
    借书
    :param title: 借出的书籍名称
    '''
    for i in self.books:
      if i.get_title() == title:
        self.books.remove(i)
        return
    print("没有这本书")


  def return_book(self, book):
    '''
    还书
    :param book: 还回的书籍对象
    '''
    for i in self.origin_books:
      if i.get_title() == book.get_title():
        self.books.append(book)
        print("还书成功，欢迎再来！")
        return
      else:
        continue
    print("所还书籍非本图书馆原有书籍，还书失败！")

  def show_books(self):
    for i in self.books:
      print(f"书名：{i.get_title()}，作者：{i.get_author()}，出版年份{i.get_pubdate()}")


# 创建对象
book1 = Book("Pride and Prejudice", "Jane Austen", "1813")
book2 = Book("Le Petit Prince", "Antoine de Saint-Exupéry", "1942")
book3 = Book("Jane Eyre", "Charlotte Brontë", "1847")

lib = Library("学校图书馆")
books_list = [book1, book2, book3]
for b in books_list:
  lib.add_book(b)
print("本图书馆拥有如下书籍：")
lib.show_books()
lib.borrow_book("Le Petit Prince")
lib.borrow_book("Jane Eyre")
print("借出书籍后，所剩书籍如下：")
lib.show_books()
print(f"归还书籍{book2.get_title()}")
lib.return_book(book2)
print("归还书籍后，所剩书籍如下：")
lib.show_books()
